Relational Database Design and Modeling for Software Engineers
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
Course Overview
Before the Advent of Database
Fundamental Concepts
What is a Database?
Database management systems (DBMS)
Overview of Relational Databases
Relational Vs. Non-Relational Databases
Data Modeling
Introduction to Data Modeling
Levels of Data Modeling
Data Modeling Process
Best Practices in Data Modeling
Quiz
Entity-Relationship (ER) Data Modeling
Introduction to ER Models
Entities, Attributes, and Relationships
Cardinality and Participation
Attributes of Relationship Types
Weak Entity Types
Creating an ER Diagram for Employee Management System
Quiz
The Relational Data Model
Introduction to the Relational Model
Relations, Tuples, and Attributes
Keys in Relational Databases
Relational Integrity Constraints
Converting ER Diagrams to Relational Model
Best Practices for ER Diagrams to Relational Models
Quiz
Introduction to Functional Dependency
Types of Functional Dependencies
Inference Rules for Functional Dependencies
Closure of Attribute Sets
Quiz
Introduction to Normalization
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
Higher Normal Forms (4NF, 5NF)
Exercise 1
Solution to Exercise 1
Exercise 2
Solution to Exercise 2
Designing a Hospital Management System
Designing a Hotel Management System
Designing a Bank Management System
Designing an Instagram
Designing an E-commerce Platform
Designing an Online Food Delivery System
Best Practices for ER Diagrams to Relational Models

While the process of converting simple ER diagrams to relational models may seem straightforward, handling complex diagrams requires additional consideration. This section outlines best practices for managing advanced features such as composite attributes, multivalued attributes, various types of relationships, and relationship attributes.

1. Handling Composite Attributes

Composite attributes are attributes that can be broken down into smaller sub-attributes (e.g., Full_Name → First_Name, Middle_Initial, Last_Name).

Best Practice:

  • Do not store composite attributes as a single column in the relational model. Instead:
    • Break down the composite attribute into its constituent parts.
    • Create separate columns for each sub-attribute.

Example:

  • ER Attribute: Full_Name
  • Relational Model Columns: First_Name, Middle_Initial, Last_Name

2. Handling Multivalued Attributes

Multivalued attributes are those that can have multiple values for a single entity (e.g., an employee having multiple contact numbers).

Best Practice:

  • Create a separate table to handle multivalued attributes.
  • Use a foreign key to link this new table back to the original entity.
  • The new table should include:
    • A column for the multivalued attribute.
    • A column for the foreign key referencing the primary key of the original table.

Example:

  • ER Attribute: Contact_Number (multivalued for Employee)
  • Relational Tables:
    1. Employee Table: Employee_ID (PK), other attributes
    2. Employee_Contact Table: Employee_ID (FK), Contact_Number

3. Handling Derived Attributes

Derived attributes are calculated from other attributes rather than being stored directly in the database. Here’s how to handle them effectively:

  1. Avoid Storing Derived Attributes:

    • Calculate them dynamically in queries to prevent redundancy and inconsistencies.
    • Example: Use Birthdate to calculate Age during retrieval.
  2. Store Only When Necessary:

    • Store derived attributes if the computation is complex, expensive, or used frequently.
    • Example: Net_Pay derived from Gross_Salary and Tax_Deductions.

4. Converting Relationships

a. One-to-One Relationships

  • Represent by adding the primary key of one entity as a foreign key in the other entity’s table.
  • Decide which table should hold the foreign key based on dependency or access patterns.

Example:

  • Relationship: Employee ↔ Payroll
  • Relational Tables:
    • Employee Table: Employee_ID (PK), other attributes
    • Payroll Table: Payroll_ID (PK), Employee_ID (FK), other attributes

b. One-to-Many Relationships

  • Add the primary key of the "one" side as a foreign key in the "many" side table.

Example:

  • Relationship: Department (1) ↔ Employee (many)
  • Relational Tables:
    • Department Table: Department_ID (PK), other attributes
    • Employee Table: Employee_ID (PK), Department_ID (FK), other attributes

c. Many-to-Many Relationships

  • Create a new table (junction table) to represent the relationship.
  • The new table should include:
    • Primary keys from both participating entities as foreign keys.
    • Any additional attributes related to the relationship.

Example:

  • Relationship: Student ↔ Course
  • Relational Tables:
    1. Student Table: Student_ID (PK), other attributes
    2. Course Table: Course_ID (PK), other attributes
    3. Enrollment Table: Student_ID (FK), Course_ID (FK), Enrollment_Date (relationship attribute)

5. Managing Weak Entities

Weak entities are entities that do not have sufficient attributes to form a primary key and rely on a strong entity.

Best Practice:

  • Convert the weak entity into a separate table.
  • Include a foreign key referencing the strong entity’s primary key.
  • Combine the foreign key and weak entity’s identifying attributes to form the composite primary key.

Example:

  • Weak Entity: Dependent (for Employee)
  • Relational Tables:
    1. Employee Table: Employee_ID (PK), other attributes
    2. Dependent Table: Employee_ID (FK), Dependent_Name (part of PK), Relationship

6. Normalization to Avoid Redundancy

After converting the ER diagram to a relational model:

  1. Check for Redundancies: Ensure there are no duplicate data values in tables.
  2. Normalize: Apply normalization rules (1NF, 2NF, 3NF, BCNF) to eliminate anomalies and ensure data integrity.

7. Tips for Large and Complex Diagrams

  • Modular Design: Break down large diagrams into smaller, manageable modules, focusing on specific entities and their relationships.
  • Hierarchy of Relationships: Address simpler relationships (one-to-one and one-to-many) before tackling many-to-many relationships and relationship attributes.
  • Documentation: Clearly document assumptions, attribute definitions, and decisions made during the conversion.
Converting ER Diagrams to Relational Model
Quiz
Mark as Completed

On this page

  1. Handling Composite Attributes
  1. Handling Multivalued Attributes
  1. Handling Derived Attributes
  1. Converting Relationships
  1. Managing Weak Entities
  1. Normalization to Avoid Redundancy
  1. Tips for Large and Complex Diagrams